package com.o2o.etl_data.jd.brandv1.UpdataTable_new.utils

import org.apache.spark.sql.{DataFrame, SparkSession}

class brand_state_util {

  def brand_state(brand_stap_2:DataFrame, spark:SparkSession, platformName:String): DataFrame ={
//    新增品牌

    brand_stap_2.registerTempTable("addNewBrand")
//    println("新增品牌注册表成功！")

//   品牌来源国表
    val state_1 = spark.read.option("header","true")
      .csv("s3a://o2o-dataproces-group/li_yinchao/Table/2019/brand_stateTable/brand_stateTable_end.csv")
      .where("brand_state != '-1' and brand_state != '0'")
      .dropDuplicates("brandName_cn")

//    缓存
    state_1.registerTempTable("brand_stateTables")
//    println("品牌来源国注册表成功")


    val stateResult = spark.sqlContext.sql(
      """
        |select
        |b.*,
        |a.brand_state as state
        |from
        |brand_stateTables a
        |join
        |addNewBrand b
        |on a.brandName_cn = b.brandName_cn
      """.stripMargin)
      .dropDuplicates("brandCcId")
      .drop("brand_state")
      .withColumnRenamed("state", "brand_state")

//    println("品牌 和 品牌来源国关联")


    return stateResult
  }

}
